package com.example.testlist.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import com.example.testlist.R;
import com.gemall.library.hepler.GlideImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;

public class HomeBanner extends LinearLayout {

    Context mContext;
    Banner mBanner;

    private ArrayList<String> list_path = new ArrayList<>();
    private ArrayList<String> list_title = new ArrayList<>();

    public HomeBanner(Context context) {
        this(context, null);
    }

    public HomeBanner(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public HomeBanner(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        inflate(mContext, R.layout.home_banner,this);
        mBanner = findViewById(R.id.banner);

        initView();
        setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,400));
    }



    private void initView() {
        list_path.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1573734724247&di=b4adb534802f3ae998e845d6356af5e7&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01b21f56ab021e6ac7256cb02783b6.jpg%402o.jpg");
        list_title.add("123");

        list_path.add("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=24759109,224248604&fm=26&gp=0.jpg");
        list_title.add("夏款女装定制");

        //设置banner样式
        mBanner.setBannerStyle(BannerConfig.CENTER);
        //设置banner动画效果
        mBanner.setBannerAnimation(Transformer.DepthPage);
        mBanner.isAutoPlay(true);
        //设置轮播间隔时间
        mBanner.setDelayTime(3000);
        mBanner.setBannerTitles(list_title);
        //简单使用
        mBanner.setImages(list_path)
                .setImageLoader(new GlideImageLoader())
                .setOnBannerListener(new OnBannerListener() {
                    @Override
                    public void OnBannerClick(int position) {

                    }
                })
                .start();

    }



}
